package UserInfoTest;

import com.yang.MainController;
import com.yang.mapper.ArchivesMapper;
import com.yang.mapper.RoleMapper;
import com.yang.mapper.UserInfoMapper;
import com.yang.pojo.Archives;
import com.yang.pojo.Role;
import com.yang.pojo.UserInfo;
import com.yang.service.UserInfoService;
import com.yang.util.EntityUtil;
import com.yang.util.NumberGeneration;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author 杨天可
 * @Date 2021/3/9 16:58
 * @Version 1.0
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = MainController.class)
public class UserInfoOperation {

    /***
     * 更新员工编号
     */
    @Resource
    UserInfoMapper userInfoMapper;
    @Resource
    ArchivesMapper archivesMapper;
    @Test
    public void testOne() throws Exception{
        try{
            NumberGeneration numberGeneration = new NumberGeneration();
            List<UserInfo> userInfos = userInfoMapper.selectAll();
            List<Archives> archives = archivesMapper.selectAll();
            for(UserInfo userinfo: userInfos){
                String s = numberGeneration.jobNumber(userinfo.getDepartmentId(), userinfo.getPhoneNumber());
                for(Archives archive: archives){
                    if(archive.getUserId() == userinfo.getId()){
                        archivesMapper.updateJobNum(s,archive.getId());
                        break;
                    }
                }

            }
        }catch (Exception e){
            e.printStackTrace();
        }


    }
    @Resource
    RoleMapper roleMapper;
    @Resource
    UserInfoService userInfoService;
    @Test
    public void testTwo(){
        UserInfo userinfo = userInfoService.findById(1);
        Role byId = roleMapper.findById(userinfo.getRoleId());
        userinfo.setRole(byId);
        System.out.println(userinfo);
    }

}
